import request from '@/router/axios'
import { userInfo, tableData } from '@/mock/user'
import { menu, menuAll } from '@/mock/menu'
import { baseUrl } from '@/config/env'
// export const loginByUsername = (username, password, code, redomStr) => {
//     return new Promise((resolve, reject) => {
//         resolve({ data: new Date().getTime() });
//     })
// }

//TODO FIXIT
export const loginByUsername =(username, password, code, redomStr) => {
    return new Promise((resolve, reject) => {

        var data = "username=" + username + "&password=" + password + "&captcha=" + code;
        //请求后端
        alert(data);


        return request({
          url: 'http://localhost:8080/sys/login',
          method: 'post',
          data: {
            username,
            password,
            code
          }
        }).then(response => {
            // const data = response.data;
            // commit('SET_NAME', data.name);
            // commit('SET_TOKEN', data.token);
            // setName(data.name);
            // setToken(data.token);
            resolve(response); }).catch(error => { reject(error) })

        //
        // this.$http.post( 'sys/login', {
        // param: data}).then((result) => {
        //   if (result.code == 0) {//登录成功
        //       resolve({ data: new Date().getTime() });
        //   }else {
        //     reject();
        //   }
        // });

      })
}

export const getUserInfo = () => {
    return new Promise((resolve, reject) => {
        resolve({ data: userInfo });
    })
}
export const RefeshToken = () => {
    return new Promise((resolve, reject) => {
        resolve({ data: new Date().getTime() });
    })
}

export const getMenu = (parentId) => {
    return new Promise((resolve, reject) => {
        if (parentId != 1) parentId = 0;
        resolve({ data: menu[parentId] });
    })
}
export const getMenuAll = () => {
    return new Promise((resolve, reject) => {
        resolve({ data: menu[0] });
    })
}

export const getTableData = (page) => {
    return new Promise((resolve, reject) => {
        resolve({ data: tableData });
    })
}
export const logout = () => {
    return new Promise((resolve, reject) => {
        resolve();
    })
}
